﻿/*彻底避免浏览器记住密码！
只支持从尾部追加/删除

用法：
<input id="ctlFace" type="text" oninput="Shadow(event,'ctlFace','ctlShadow);"/>
<input id="ctlShadow" type="hidden" />

*/
function Shadow(/*event,*/ ctlFace, ctlShadow) {
    var ori_len = document.getElementById(ctlShadow).value.length;
    var new_len = document.getElementById(ctlFace).value.length;
    if (new_len - ori_len == 1)//append the new character to the tail!
    {
        //var new_char = event.target.value.substr(new_len - 1, 1);
        var new_char = document.getElementById(ctlFace).value.substr(new_len - 1, 1);
        document.getElementById(ctlShadow).value = document.getElementById(ctlShadow).value + new_char;

        new_char = "";
        for (i = 0; i < new_len; i++)
            new_char = new_char + "•";
        document.getElementById(ctlFace).value = new_char;
        //return;
    }
    /*else if (ori_len == new_len)//impossible
        return;*/
    else if (new_len - ori_len == -1)//delete the last character.
    {
        document.getElementById(ctlShadow).value = document.getElementById(ctlShadow).value.substr(0, new_len);
        //return;
    }
    else if (Math.abs(new_len - ori_len) > 1)//synchronization failed, reset!
    {
        document.getElementById(ctlShadow).value = "";
        document.getElementById(ctlFace).value = "";
        //return;
    }
    
    //alert(document.getElementById(ctlShadow).value);
    //return;
}